﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using XDL.Framework;
using XDL.Framework.Messaging;
using JumpNFight.Weapons;
using XDL.Framework.Particles;

namespace JumpNFight.Simulation
{
    class BadGuy :
        NPCBase
    {
        public const int SpawnSuperBadGuyEvent = 6001;

        public bool IsSuper
        {
            get;
            private set;
        }

        public override int NPCType
        {
            get 
            {
                return IsSuper ? 1 : 0;
            }
        }

        Moveable m_moveable;
        public override Moveable Moveable
        {
            get 
            {
                return m_moveable;
            }
        }

        public BadGuy(int id, Game game) :
            this(id,game,false)
        {
        }

        public BadGuy(int id, Game game, bool isSuper) :
            base(id,game)
        {
            this.IsSuper = isSuper;
            m_moveable = new Moveable(id);
            m_moveable.Mass = 150;
            m_moveable.MaxSpeed = isSuper?240:170;
        }

        public override void Update(GameTime gameTime)
        {
            if (IsAlive)
            {
                // only things that badguy can do: run!!
                Moveable.Move(new Vector2(IsRunningRight ? 1 : -1, 0));
            }

            //
            base.Update(gameTime);
        }

        public override bool ProcessEvent(GameTime gameTime, int msgId, EventArgs e)
        {
            switch (msgId)
            {
                case World.HitLeftTileEvent:
                    IsRunningRight = true;
                    break;

                case World.HitRightTileEvent:
                    IsRunningRight = false;
                    break;

                case NPCBase.DieEvent:
                    LastHitTime = gameTime.TotalGameTime;
                    // notify world that a bad guy died from the "recycle fire"
                    if (!IsSuper )
                        GameServices.EventDispatcher.PostEvent(World.ID, BadGuy.SpawnSuperBadGuyEvent, null);

                    Kill(gameTime, Vector2.Zero);
                    break;

                case TheMaskWeaponSystem.BouhEvent:
                    IsRunningRight = !IsRunningRight;
                    break;

                default:
                    base.ProcessEvent(gameTime, msgId, e);
                    break;
            }

            return true;
        }
    }
}
